import java.util.*;

import static com.sun.java.accessibility.util.TopLevelWindowMulticaster.remove;

//二叉搜索树
public class BinarySearchTree {
    static class TreeNode{
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val){
            this.val = val;
        }
    }

    public TreeNode root;

    public TreeNode search(int key){
        TreeNode cur = root;

        while (cur != null){
            if (cur.val > key){
                cur = cur.left;
            }else if (cur.val < key){
                cur = cur.right;
            }else{
                return cur;
            }
        }

        return null;
    }

    public static void main1(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        map.put("c", 1);
        map.put("b", 2);
        map.put("a", 3);
        map.put("z", 18);

//        Set<String> set = map.keySet();//set里面只有a、b2个元素
//        System.out.println(map.get("a")); //2
//
//        System.out.println(map.get("b")); //2
//        System.out.println(map.get("c"));//null
//        System.out.println(map.getOrDefault("c", 10));//10

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        for (Map.Entry<String, Integer> entry : entrySet){
            System.out.println("key: "+ entry.getKey() + ",val: " + entry.getValue());
        }
    }

    public static void main(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("h");
        set.add("a");
        set.add("i");

        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
